define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'property/repertory/index' + location.search,
                    //add_url: 'medicine/storage/add',
                    //edit_url: 'medicine/storage/edit',
                    //del_url: 'medicine/storage/del',
                    fors_url: 'property/repertorys/index',
                    multi_url: 'property/repertory/multi',
                    import_url: 'property/repertory/import',
                    table: 'repertory',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: '',
                commonSearch: true,
                searchFormVisible: true,
                visible: false,
                showToggle: false,
                showColumns: false,
                search:false,
                showExport: true,
                columns: [
                    [
                        {checkbox: true},
                        // {field: 'id', title: __('序号'), formatter: function(value, row, index){
                        //         return ++index;
                        //     },operate: false},
                        {field: 'id', title: __('入库编号'), operate: false},
                        {field: 'vindicate.id', title: __('物品编号'), operate: false},
                        {field: 'vindicate.name', title: __('物品名称'), operate: 'LIKE'},
                        {field: 'vindicate.specification', title: __('规格（单位）'), operate: false},
                        {field: 'count', title: __('库存'),searchList: {"1":__('从多到少'),"2":__('从少到多')}},
                        {field: 'price', title: __('采购价'), operate: false},
                        {field: 'counts', title: __('采购数量'), operate: false},
                        {field: 'create_time', title: __('创建时间'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        //{field: 'image', title: __('图片'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        //{field: 'status', title: __("状态"), searchList: {"0":__('未发布'),"1":__('已发布')}, formatter: Table.api.formatter.status},

                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table,
                        //     events: Table.api.events.operate,
                        //     // buttons: [{
                        //     //     name: 'detail',
                        //     //     text: __('Detail'),
                        //     //     icon: 'fa fa-list',
                        //     //     classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                        //     //     url: 'test/detail'
                        //     // }],
                        //     formatter: Table.api.formatter.operate
                        // }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'test/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'title', title: __('Title'), align: 'left'},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '130px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'test/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'test/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});